package me.zhengjie.modules.system.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.service.ApplyListService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequiredArgsConstructor
@Api(tags = "系统：流程配置管理")
@RequestMapping("/api/applyList")
public class ApplyListController {
    private final ApplyListService applyListService;

    @GetMapping(value = "/getProcessApplyList")
    @ApiOperation("获取流程申请列表")
    @Log("获取流程申请列表")
    @AnonymousAccess
    public ResponseEntity<Object> getProcessDefine(){
        return new ResponseEntity<>(applyListService.getProcessDefine(), HttpStatus.OK);
    }

    @PostMapping(value = "/getApprover")
    @ApiOperation("获取流程审批人员")
    @Log("获取流程审批人员")
    @AnonymousAccess
    public ResponseEntity<Object> getApproverName(@RequestBody Long id){
        return new ResponseEntity<>(applyListService.getApproveUsers(id), HttpStatus.OK);
    }

    @PostMapping(value = "/initiateProcess")
    @ApiOperation("发起流程")
    @Log("发起流程")
    @AnonymousAccess
    public ResponseEntity<Object> initiateProcess(@RequestBody Map<String,Object> map){
        applyListService.initiateProcess(map);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
